<%--
    Document   : loanRequest
    Created on : 04 14, 11, 15:27:20 PM
    Author     : MonicaSandoval
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib  prefix="s" uri="/struts-tags" %>
<%@taglib  prefix="sj" uri="/struts-jquery-tags" %>
<%@taglib  prefix="sjg" uri="/struts-jquery-grid-tags" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>


<div id="preapproved" style="width: 100%">

    <s:url id="loanappurl" value="loanprofile-loanapp.jsp" />
    <script type="text/javascript">
        var y = 0;
            
        $.subscribe("gridCompleteTopics",function() {
            var ids = document.getElementById("selected").value;
            jQuery.each(y,function(index, item) {
                jQuery("#gridtable").jqGrid("setSelection", item);
            });
            jQuery.each(ids,function(index, item) {
                var flag = false;
                for(var prop in y){
                    if(item == y[prop]){
                        flag = true;
                    }
                }
                
                if(!flag){
                    jQuery("#gridtable").jqGrid("setSelection", item);
                }                                   
            });
            y = document.getElementById("selected").value;
        });

        $.subscribe('getselectedids', function(event,data) {
            var s = $("#gridtable").jqGrid('getGridParam','selarrrow');
            document.getElementById("selected").value = s;
            check();
        });

        function check(){

            if(document.getElementById("selected").value.length != 0){
                while(document.getElementById("createReq").hasAttribute("style")){
                    document.getElementById("createReq").removeAttribute("style");
                    document.getElementById("viewProf").removeAttribute("style");
                }
                
            }else{
                document.getElementById("createReq").style.display = "none";
                document.getElementById("viewProf").style.display = "none";
            }
        }
                        
        function proceedButton(){
            document.genreq.submit();                
        }
        function cancelButton(){
            $('#dialog').dialog('close');
        }
          

        function formatLink(cellvalue, options, rowObject) {
            return "<a href='<s:property value="loanappurl" />?id="+rowObject["loanverificationid"]+"' onClick='javascript: return openDialog(this)'>" + cellvalue + "</a>";
        }
        function openDialog(e) {
            window.open(e.href, "newWindow");
            return false;
        }
    </script>
    <s:url id="remoteurl" action="loanRequest"/>
    <sjg:grid
        id="gridtable"
        caption="Pre-Approved Loans"
        dataType="json"
        href="%{remoteurl}"
        gridModel="gridModel"
        pagerButtons="true"
        pagerInput="true"
        rowNum="15"
        rowList="10,15,20"
        loadingText="Loading..."
        width="930"
        shrinkToFit="true"
        pager="true"
        reloadTopics = "reloadItems"
        navigator="true" 
        navigatorEdit="false"
        navigatorView="true"
        navigatorDelete="false"
        navigatorAdd="false"
        navigatorSearch="true"
        navigatorRefresh="true"
        onCompleteTopics="gridCompleteTopics"
        onSelectRowTopics="getselectedids"
        multiselect="true"
        >
        <sjg:gridColumn name="loanverificationid" index="loanverificationid" title="Loan Verification No." key="true" hidedlg="true" hidden="true" />
       <sjg:gridColumn name="documentno" index="documentno" title="Document No." sortable="true" formatter = "formatLink" search="true" searchoptions="{sopt:['eq']}" align="center" cssClass="gridlink"/>
        <sjg:gridColumn name="borrowername" index="borrowername" title="Borrower Name" sortable="true" search="true" searchoptions="{sopt:['eq']}"/>
        <sjg:gridColumn name="amountapplied" index="amountapplied" title="Amount Applied" formatter="currency" align="right"/>
        <sjg:gridColumn name="amountrequested" index="amountrequested" title="Amount Requested" formatter="currency" align="right" />
       <sjg:gridColumn name="areaname" index="areaname" title="Area" search="true" searchoptions="{sopt:['eq']}" align = "center" sortable="true"/>
        <sjg:gridColumn name="applicationdate" index="applicationdate" title="Date of Application" align="center" search="true" searchoptions="{sopt:['eq']}" />
       
    </sjg:grid>


    <br/>
    <hr/>
    <sj:dialog
        id="dialog"
        autoOpen="false"
        modal="true"
        buttons = "{
        'Proceed':function() { proceedButton(); },
        'Cancel':function() { cancelButton(); }
        }"
        title="Generate Loan"
        >
        You are now about to generate a Loan Request Report.
        <s:form name="genreq" action="/loanrequest.jsp?cat=branchcash" method="post" >
            <s:textfield name="selected" id="selected" value="" cssStyle="display:none" />
        </s:form>
    </sj:dialog>
    <sj:a
        name="createReq"
        id="createReq"
        openDialog="dialog"
        button="true"
        buttonIcon="ui-icon-newwin"
        cssStyle="display:none"
        >
        Generate Loan Request
    </sj:a>

</div>
